<?php


declare (strict_types=1);

namespace app\bbxw\controller\api;


use app\bbxw\service\PaymentService;

use think\admin\extend\CodeExtend;
use app\bbxw\controller\api\Auth;
use think\admin\Controller;

/**
 * 订单数据
 * @class Test
 * @package app\wechat\controller\api
 */
class Order extends Controller
{
   // protected $user_id = 1;
    public function getList()
    {
        $customer_id = $this->request->get('id');
        $type = $this->request->get('type');
        $date_type = $this->request->get('date_type');
        $where['status'] = 1;

        if($type==1){
            $where['customer_id'] = $customer_id;
        }else{
            $power_source_name = $this->app->db->name("power_source")->where(['id'=>$customer_id])->value('name');
            $where['power_source'] = $power_source_name;
        }
        $dates = [];
        $page = $this->request->get('page',1);

        for ($i = ($page-1)*7; $i < $page*7; $i++) {
            $currentDate = date('Y-m-d', strtotime("-$i day"));
            $currentMonth = date('Y-m', strtotime($currentDate));
            $currentYear = date('Y', strtotime($currentDate));
            $thisMonth = date('Y-m');
            $thisYear = date('Y');
            if($date_type=='month'){
                if ($currentMonth > $thisMonth) {
                    $this->success('获取成功',['list'=>[]]);
                }
            }
            if($date_type=='year'){
                if ($currentYear > $thisYear) {
                    $this->success('获取成功',['list'=>[]]);
                }
            }
            $dates[] = $currentDate;

        }
        $weeks = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
        $weeks_en = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
        $list = [];
        foreach ($dates as $k=>$v){
            $list[$k]['business_amount'] = $this->app->db->name("play_accompany")->where($where)
                ->whereDay("date",$v)->order('date desc')->sum('business_amount');
            $list[$k]['date'] = $v;
            $week = date('w',strtotime($v));
            $list[$k]['week'] = $weeks[$week];
            $list[$k]['week_en'] = $weeks_en[$week];
        }
        $this->success('获取成功',['list'=>$list]);

    }

}
